package com.ruoyi.web.controller.stock;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.StockLt;
import com.ruoyi.system.service.IStockLtService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 龙头库Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/stock/lt")
public class StockLtController extends BaseController
{
    @Autowired
    private IStockLtService stockLtService;

    /**
     * 查询龙头库列表
     */
    @PreAuthorize("@ss.hasPermi('stock:lt:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockLt stockLt)
    {
        startPage();
        List<StockLt> list = stockLtService.selectStockLtList(stockLt);
        return getDataTable(list);
    }

    /**
     * 导出龙头库列表
     */
    @PreAuthorize("@ss.hasPermi('stock:lt:export')")
    @Log(title = "龙头库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockLt stockLt)
    {
        List<StockLt> list = stockLtService.selectStockLtList(stockLt);
        ExcelUtil<StockLt> util = new ExcelUtil<StockLt>(StockLt.class);
        util.exportExcel(response, list, "龙头库数据");
    }

    /**
     * 获取龙头库详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:lt:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(stockLtService.selectStockLtByRecordId(recordId));
    }

    /**
     * 新增龙头库
     */
    @PreAuthorize("@ss.hasPermi('stock:lt:add')")
    @Log(title = "龙头库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockLt stockLt)
    {
        return toAjax(stockLtService.insertStockLt(stockLt));
    }

    /**
     * 修改龙头库
     */
    @PreAuthorize("@ss.hasPermi('stock:lt:edit')")
    @Log(title = "龙头库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockLt stockLt)
    {
        return toAjax(stockLtService.updateStockLt(stockLt));
    }

    /**
     * 删除龙头库
     */
    @PreAuthorize("@ss.hasPermi('stock:lt:remove')")
    @Log(title = "龙头库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(stockLtService.deleteStockLtByRecordIds(recordIds));
    }
}
